<?php

namespace App\Entity;

use App\Enum\LogTypeEnum;
use App\Repository\MenuRepository;
use App\Utils\Helper\LogHelper;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;

/**
 * @ORM\Entity(repositoryClass=MenuRepository::class)
 * @UniqueEntity("alias")
 * @ORM\HasLifecycleCallbacks()
 */
class Menu {
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=255)
     */
    private $title;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $description;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $url;

    /**
     * @ORM\Column(type="integer", nullable=true)
     */
    private $page_category_id;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $style;

    /**
     * @ORM\Column(type="string", length=255)
     */
    private $alias;

    /**
     * @ORM\Column(type="integer", nullable=true, options={"default"="1"})
     */
    private $position = 1;

    /**
     * @ORM\Column(type="integer", nullable=true)
     */
    private $admin_user_id;

    /**
     * @ORM\Column(type="datetime", nullable=true)
     */
    private $created_at;

    /**
     * @ORM\Column(type="datetime", nullable=true)
     */
    private $updated_at;

    public function getId (): ?int {
        return $this->id;
    }

    public function getTitle (): ?string {
        return $this->title;
    }

    public function setTitle (string $title): self {
        $this->title = $title;

        return $this;
    }

    public function getUrl (): ?string {
        return $this->url;
    }

    public function setUrl (?string $url): self {
        $this->url = $url;

        return $this;
    }

    public function getPageCategoryId (): ?int {
        return $this->page_category_id;
    }

    public function setPageCategoryId (?int $page_category_id): self {
        $this->page_category_id = $page_category_id;

        return $this;
    }

    public function getStyle (): ?string {
        return $this->style;
    }

    public function setStyle (string $style = null): self {
        $this->style = $style;

        return $this;
    }

    public function getPosition (): ?int {
        return $this->position;
    }

    public function setPosition (?int $position): self {
        $this->position = $position;

        return $this;
    }

    public function getAdminUserId (): ?int {
        return $this->admin_user_id;
    }

    public function setAdminUserId (?int $admin_user_id): self {
        $this->admin_user_id = $admin_user_id;

        return $this;
    }

    public function getCreatedAt (): ?\DateTimeInterface {
        return $this->created_at;
    }

    public function setCreatedAt (?\DateTimeInterface $created_at): self {
        $this->created_at = $created_at;

        return $this;
    }

    public function getUpdatedAt (): ?\DateTimeInterface {
        return $this->updated_at;
    }

    public function setUpdatedAt (?\DateTimeInterface $updated_at): self {
        $this->updated_at = $updated_at;

        return $this;
    }

    public function getAlias (): ?string {
        return $this->alias;
    }

    public function setAlias (string $alias): self {
        $this->alias = $alias;

        return $this;
    }

    public function getDescription (): ?string {
        return $this->description;
    }

    public function setDescription (?string $description): self {
        $this->description = $description;

        return $this;
    }

    /**
     * 新建之后 日志
     * @ORM\PostPersist()
     */
    public function buildLogByCreate () {
        $description = '名称:['.$this->getTitle().'] 别名:['.$this->getAlias().']';
        LogHelper::buildLog(LogTypeEnum::TYPE_MENU_CREATE, $description);
    }

    /**
     * 更新之后 日志
     * @ORM\PostUpdate()
     */
    public function buildLogByUpdate () {
        $description = '名称:['.$this->getTitle().'] 别名:['.$this->getAlias().']';
        LogHelper::buildLog(LogTypeEnum::TYPE_MENU_UPDATE, $description, $this);
    }

    /**
     * 删除之前 日志
     * @ORM\PreRemove()
     */
    public function buildLogByDelete () {
        $description = '名称:['.$this->getTitle().'] 别名:['.$this->getAlias().']';
        LogHelper::buildLog(LogTypeEnum::TYPE_MENU_DELETE, $description, $this);
    }
}
